package cn.zbacm.api.util;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.Map;

@Getter
@Setter
@RequiredArgsConstructor
public class ServiceResult<T> {
  @JsonIgnore
  @NonNull
  private Boolean success;

  private int messageCode = -1;

  private String messageDetail = "";

  private boolean messageVisible = true;

  private T data;

  @Deprecated
  @JsonIgnore
  public Map getMessageCodeBody() {
    return Collections.singletonMap("messageCode", messageCode);
  }

  public void markAsSuccess() {
    success = true;
  }

  public boolean isSuccess() {
    return success;
  }

  @JsonIgnore
  @Autowired
  private ModelMapper modelMapper;
}
